﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    static class validator
    {
        /*
         * int[3] start: data regarding the piece being moved
         * index 0: color
         * index 1: x_loc
         * index 2: y loc
         * 
         * int[8,8] board: the data of the board
         * 
         * int horiz_dir: either +-1 or 0. +-1 tells if the pieces are going down(-1, red), up(1, black), or king (0, all)
         * 
         * will return the info of the validity of the move
         * 
         * valid[0] == 0: invalid move
         * valid[0] == 1: empy tile
         * valid[0] == 2: enemy chip
         * 
         * valid[1] = x_loc
         * 
         * valid_2 = y_loc
         * 
         */
        static int[] validate_move(int[] start, int[,] board, int horiz_dir)
        {
            int[] valid = new int[3];

            int color_start = start[0];
            int x_start = start[1];
            int y_start = start[2];

            int vert_dir = color_start / (int)(Math.Abs((decimal)color_start));

            int new_x = x_start + horiz_dir;
            int new_y = y_start + vert_dir;


            //if the destination tile is out of bounds
            if (new_x < 0 || new_y < 0 || new_x > 8 || new_y > 8)
            {
                valid[0] = 0;
            }
            else
            {
                //if the destination tile is player's chip
                if (board[new_x, new_y] == color_start || board[new_x, new_y] == color_start * 2)
                {
                    valid[0] = 0;
                }
                // if the destination tile is empty
                else if (board[new_x, new_y] == 0)
                {
                    valid[0] = 1;
                }
                // if the destination tile is enemy chip
                else
                {
                    valid[0] = 2;
                }
            }

            valid[1] = new_x;
            valid[2] = new_y;

            return valid;
        }

        /*
         * creates a list of valid moves
         * 
         * int[3] s_piece: data regarding the selected piece
         * index 0: color of piece
         * index 1: x_loc
         * index 2: y_loc
         * 
         * int[8,8] board: the data for the board
         * 
         * return value is a list of int[2]. These represent the x,y coordinates of valid moves.
         * 
         * this list will start as just length 2, which are the two valid moves
         * 
         * contemplating adding list of possible (but invalid) moves so the user can see where they could move.
         * 
         */
        static List<int[]> calculate_valid_moves(int[] s_piece, int[,] board)
        {
            List<int[]> valid_moves = new List<int[]>();

            int[] left_valid = new int[3];
            int[] right_valid = new int[3];

            left_valid = validate_move(s_piece, board, -1);
            right_valid = validate_move(s_piece, board, 1);

            switch (left_valid[0])
            {
                case 0:
                    //do nothing. might add something here if we want to show invalid moves
                    break;
                case 1:
                    //allow move to empty spot
                    int[] valid_move = new int[2];

                    int[] loc = new int[2];
                    loc[0] = left_valid[0];
                    loc[1] = left_valid[1];

                    valid_moves.Add(loc);
                    break;
                case 2:
                    //check for jumps
                    break;
                default:
                    break;
            }

            return valid_moves;
        }

        /*
         * checks to see if the jump is valid. if it is, returns the loc of the jump.
         * 
         * int[3] s_piece: data for the selected piece.
         * index 0: color
         * index 1: x_loc
         * index 2: y_loc
         * 
         * int[2] jump_piece: location of the piece being jumped
         * index 0: x_loc
         * index 1: y_loc
         * 
         * int[8,8] board: data of the board
         * 
         * this function calculates if it is possible to do a jump, and returns the coordinates of the landing spot.
         * returns [-1, -1] if it is an invalid jump (i.e. there is a piece at the landing)
         * 
         * does this really need to be done? can't we just use the validate move again to calculate this? I think so
         * 
         */
        static int[] validate_jump(int[] s_piece, int[] jump_piece, int[] board)
        {
            int[] valid = new int[3];

            int color_s_piece = s_piece[0];
            int x_s_piece = s_piece[1];
            int y_s_piece = s_piece[2];

            int color_jump_piece = jump_piece[0];
            int x_jump_piece = jump_piece[1];
            int y_jump_piece = jump_piece[2];

            //check moves for normal pieces
            if (Math.Abs((decimal)color_s_piece) == 1)
            {
            }

            return valid;
        }
    }
}